package rpc_client_server;

import java.rmi.RemoteException;
import java.util.UUID;

/** A statement of what the client & server must agree upon. */
public interface RemoteKeyValue extends java.rmi.Remote {

	/*************************************
	 * Methods of server called by client
	 ************************************/
	/** The method used to get the value corresponding to the key. */
	public String getValue(String key) throws java.rmi.RemoteException;
	
	/** The method used to add a key-value pair. */
	public String putKeyValue(String key, String value) throws java.rmi.RemoteException;

	/** The method used to delete a key-value pair. */
	public String deleteKeyValue(String key) throws java.rmi.RemoteException;
	
	/********************************************
	 * Methods of server called by other servers (2PC Protocol)
	 ********************************************/
	public String processRequestUsingThreadPool (Request req) throws java.rmi.RemoteException;

	/** The name used in the RMI registry service. */
	public final static String LOOKUPNAME = "RemoteKeyValue";
//	public void addInRequestList(UUID theReqId) throws java.rmi.RemoteException;
//	
//	public void ackForGO(UUID reqId, int coordinatorPort) throws java.rmi.RemoteException;
//	
//	public String getName() throws java.rmi.RemoteException;
//	
//	public void sendFirstAckSignal(UUID reqId, int server) throws RemoteException;
//	
//	public void sendSecondAckSignal(UUID reqId, int server) throws RemoteException;
//	
//	public void getACKed(UUID reqId, int otherServerPort, int ackNum) throws java.rmi.RemoteException;
	
	/********************************************
	 * Methods of server called by other servers (Paxos Protocol)
	 ********************************************/
	public void paxosHandlePrepareSignalInAcceptor(
			UUID transactionId,
			int n, 
			int server) throws RemoteException;
	
	public void paxosHandlePrepareAckInProposer(
			UUID transactionId,
			boolean isPrepareOk, 
			int n,  
			UUID reqId, 
			String req, 
			String key, 
			String value,
			int otherServerPort) throws RemoteException;
	
	public void paxosHandlePrepareAckWithNullReqInProposer(
			UUID transactionId,
			boolean isPrepareOk, 
			int otherServerPort) throws RemoteException;

	public void paxosHandleAcceptSignalInAcceptor(
			UUID transactionId,
			int n, 
			UUID reqId, 
			String req, 
			String key, 
			String value,
			int server) throws RemoteException;
	
	public void paxosHandleAcceptAckInProposer(
			UUID transactionId,
			boolean isAcceptOk,
			int otherServerPort) throws RemoteException;
	
	public void paxosHandleCommitSignalInLearner(
			UUID reqId, 
			String req, 
			String key, 
			String value,
			int server) throws RemoteException;	
	
	public void addReqInMyFirstAckMap(UUID reqId, int i, boolean isAccepted) throws RemoteException;
	
	public void addReqInMySecondAckMap(UUID reqId, int i, boolean isAccepted) throws RemoteException;
	
}
